package demo5数组对象排序2;

import com.sun.corba.se.impl.orbutil.ObjectStreamClassUtil_1_3;

import java.util.Comparator;
import java.util.SplittableRandom;

class Student {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

class AgeComparator implements Comparator<Student>{
    public int compare(Student o1,Student o2){
        return o1.age-o2.age;
    }
}

class NameComparator implements Comparator<Student>{
    public int compare(Student o1,Student o2){
        return o1.name.compareTo(o2.name);
    }
}

public class Test {
    public static void main(String[] args) {
        Student student1=new Student("zhangsan",12);
        Student student2=new Student("lisi",13);

        AgeComparator ageComparator=new AgeComparator();
        System.out.println(ageComparator.compare(student1,student2));

        NameComparator nameComparator=new NameComparator();
        System.out.println(nameComparator.compare(student1,student2));
    }
}
